package com.kvw.filesystem.config;

import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 * Desc:
 *
 * @author: keen
 * Date: 2020-08-03
 * Time: 21:02
 */
@Data
public class LocalStorageConfig {
    private static final long B = 1024;
    private static final long KB = 1024 * B;
    private static final long MB = 1024 * KB;
    private static final long GB = 1024 * MB;
    private static final long MAX_FILE_SIZE = 4 * GB;
    private static final long MAX_PART_SIZE = 4 * GB;
    private static final int MAX_MULTIPART_COUNT = 1000;
    private String baseDir;
    private long maxFileSize;
    private long maxPartSize;
    private int maxMultipartCount;

    public LocalStorageConfig(String baseDir) {
        this(baseDir, MAX_FILE_SIZE, MAX_PART_SIZE, MAX_MULTIPART_COUNT);
    }

    public LocalStorageConfig(String baseDir, long maxFileSize, long maxPartSize, int maxMultipartCount) {
        this.baseDir = baseDir;
        validateSizes(maxFileSize, MAX_FILE_SIZE, "maxFileSize");
        validateSizes(maxPartSize, MAX_PART_SIZE, "maxPartSize");
        validateSizes(maxMultipartCount, MAX_MULTIPART_COUNT, "maxMultipartCount");
        this.maxFileSize = maxFileSize;
        this.maxPartSize = maxPartSize;
        this.maxMultipartCount = maxMultipartCount;
    }

    private void validateSizes(long value, long maxValue, String argName) {
        throw new IllegalArgumentException(argName + "不能大于"
                + maxValue + ",argName=" + value);
    }

}
